package algorithm.view.prepare;

import algorithm.view.common.AlgoHelpler;

import javax.swing.*;
import java.awt.*;

/**
 * @author bingo
 * @Description
 * @Date 2018/4/23
 */
public class AlgoFrame extends JFrame {

    private  int  canvasWeight ;

    private int canvasHeight;

    public AlgoFrame(String title, int canvasWeight, int canvasHeight)  {
        super(title);
        this.canvasWeight = canvasWeight;
        this.canvasHeight = canvasHeight;

         AlgoCanvas algoCanvas = new AlgoCanvas();
         setContentPane(algoCanvas);
         pack();
         setResizable(false);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setVisible(true);
    }

    public  AlgoFrame(String title){
         this(title,1024,768);
    }

    public int getCanvasWeight() {
        return canvasWeight;
    }

    public void setCanvasWeight(int canvasWeight) {
        this.canvasWeight = canvasWeight;
    }
    public int getCanvasHeight() {
        return canvasHeight;
    }
    public void setCanvasHeight(int canvasHeight) {
        this.canvasHeight = canvasHeight;
    }

    private Circle[] circles;

    public void render(Circle[] circles){
        this.circles = circles;
        repaint();
    }
    private class AlgoCanvas extends  JPanel{
        @Override
        public void paintComponent(Graphics g) {
            super.paintComponents(g);
            Graphics2D graphics2D = (Graphics2D)g;
            int strokeWeight = 1;
             AlgoHelpler.setStrokeWeight(graphics2D,strokeWeight);
             AlgoHelpler.setColor(graphics2D,Color.RED);
             for(Circle circle:circles){
                 AlgoHelpler.fillCircle(graphics2D,circle.x,circle.y,circle.getR());
             }
        }
        @Override
        public  Dimension getPreferredSize(){
            return   new Dimension(canvasWeight,canvasHeight);
        }
    }



}
